package com.seqb.manage.subject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seqb.common.mybatis.WrapperHandler;
import com.seqb.manage.subject.dao.SubjectDao;
import com.seqb.manage.subject.domain.SubjectDO;
import com.seqb.manage.subject.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;

/**
 * @author lilinshen
 * @title 科目表
 * @description 请填写相关描述
 * @date 2019-11-27
 */
@Service
public class SubjectServiceImpl implements SubjectService {
    @Autowired
    private SubjectDao subjectDao;

    @Override
    public SubjectDO get(Long id) {
        return subjectDao.selectById(id);
    }

    @Override
    public Page<SubjectDO> list(Map<String, Object> map) {
        if (null != map && null != map.get("pageNumber") && null != map.get("pageSize")) {
            PageHelper.startPage(Integer.valueOf(map.get("pageNumber").toString()), Integer.valueOf(map.get("pageSize").toString()));
        } else {
            PageHelper.startPage(1, Integer.MAX_VALUE);
        }
        QueryWrapper queryWrapper = WrapperHandler.genQueryWrapper(map, SubjectDO.class);
        return (Page<SubjectDO>) subjectDao.selectList(queryWrapper);
    }

    @Override
    public int count(Map<String, Object> map) {
        QueryWrapper queryWrapper = WrapperHandler.genQueryWrapper(map, SubjectDO.class);
        return subjectDao.selectCount(queryWrapper);
    }

    @Override
    @Transactional
    public int save(SubjectDO subject) {
        return subjectDao.insert(subject);
    }

    @Override
    @Transactional
    public int update(SubjectDO subject) {
        return subjectDao.updateById(subject);
    }

    @Override
    @Transactional
    public int remove(Long id) {
        return subjectDao.deleteById(id);
    }

    @Override
    @Transactional
    public int batchRemove(Long[] ids) {
        return subjectDao.deleteBatchIds(Arrays.asList(ids));
    }

}
